<template>
<div>
  <br>
  <el-form :inline="true">
          <el-form-item label="createDate">
<el-input v-model="searchMap.createDate" placeholder="createDate"></el-input></el-form-item>
          <el-form-item label="modifyDate">
<el-input v-model="searchMap.modifyDate" placeholder="modifyDate"></el-input></el-form-item>
          <el-form-item label="createUser">
<el-input v-model="searchMap.createUser" placeholder="createUser"></el-input></el-form-item>
          <el-form-item label="modifyUser">
<el-input v-model="searchMap.modifyUser" placeholder="modifyUser"></el-input></el-form-item>
          <el-form-item label="shopNo">
<el-input v-model="searchMap.shopNo" placeholder="shopNo"></el-input></el-form-item>
          <el-form-item label="openId">
<el-input v-model="searchMap.openId" placeholder="openId"></el-input></el-form-item>
          <el-form-item label="deliveryFee">
<el-input v-model="searchMap.deliveryFee" placeholder="deliveryFee"></el-input></el-form-item>
          <el-form-item label="totalAmount">
<el-input v-model="searchMap.totalAmount" placeholder="totalAmount"></el-input></el-form-item>
          <el-form-item label="realPayAmount">
<el-input v-model="searchMap.realPayAmount" placeholder="realPayAmount"></el-input></el-form-item>
          <el-form-item label="discountAmount">
<el-input v-model="searchMap.discountAmount" placeholder="discountAmount"></el-input></el-form-item>
          <el-form-item label="productTotalNum">
<el-input v-model="searchMap.productTotalNum" placeholder="productTotalNum"></el-input></el-form-item>
          <el-form-item label="remark">
<el-input v-model="searchMap.remark" placeholder="remark"></el-input></el-form-item>
          <el-form-item label="优惠说明">
<el-input v-model="searchMap.discountMessage" placeholder="优惠说明"></el-input></el-form-item>

    <el-button type="primary" @click="fetchData()">查询</el-button>
    <el-button type="primary" @click="handleEdit('')">新增</el-button>
  </el-form>
  <el-table
    :data="list"
    border
    style="width: 100%">
          <el-table-column prop="id" label="id" width="80"></el-table-column>
          <el-table-column prop="createDate" label="createDate" width="80"></el-table-column>
          <el-table-column prop="modifyDate" label="modifyDate" width="80"></el-table-column>
          <el-table-column prop="createUser" label="createUser" width="80"></el-table-column>
          <el-table-column prop="modifyUser" label="modifyUser" width="80"></el-table-column>
          <el-table-column prop="shopNo" label="shopNo" width="80"></el-table-column>
          <el-table-column prop="openId" label="openId" width="80"></el-table-column>
          <el-table-column prop="deliveryFee" label="deliveryFee" width="80"></el-table-column>
          <el-table-column prop="totalAmount" label="totalAmount" width="80"></el-table-column>
          <el-table-column prop="realPayAmount" label="realPayAmount" width="80"></el-table-column>
          <el-table-column prop="discountAmount" label="discountAmount" width="80"></el-table-column>
          <el-table-column prop="productTotalNum" label="productTotalNum" width="80"></el-table-column>
          <el-table-column prop="remark" label="remark" width="80"></el-table-column>
          <el-table-column prop="discountMessage" label="优惠说明" width="80"></el-table-column>

    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleEdit(scope.row.id)" type="text" size="small">修改</el-button>
        <el-button @click="handleDelete(scope.row.id)" type="text" size="small">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
      <el-pagination
      @size-change="fetchData"
      @current-change="fetchData"
      :current-page="currentPage"
      :page-sizes="[5,10,20]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>  
  <el-dialog title="编辑" :visible.sync="dialogFormVisible">
    <el-form label-width="80px">
        <el-form-item label="createDate"><el-input v-model="pojo.createDate"></el-input></el-form-item>
        <el-form-item label="modifyDate"><el-input v-model="pojo.modifyDate"></el-input></el-form-item>
        <el-form-item label="createUser"><el-input v-model="pojo.createUser"></el-input></el-form-item>
        <el-form-item label="modifyUser"><el-input v-model="pojo.modifyUser"></el-input></el-form-item>
        <el-form-item label="shopNo"><el-input v-model="pojo.shopNo"></el-input></el-form-item>
        <el-form-item label="openId"><el-input v-model="pojo.openId"></el-input></el-form-item>
        <el-form-item label="deliveryFee"><el-input v-model="pojo.deliveryFee"></el-input></el-form-item>
        <el-form-item label="totalAmount"><el-input v-model="pojo.totalAmount"></el-input></el-form-item>
        <el-form-item label="realPayAmount"><el-input v-model="pojo.realPayAmount"></el-input></el-form-item>
        <el-form-item label="discountAmount"><el-input v-model="pojo.discountAmount"></el-input></el-form-item>
        <el-form-item label="productTotalNum"><el-input v-model="pojo.productTotalNum"></el-input></el-form-item>
        <el-form-item label="remark"><el-input v-model="pojo.remark"></el-input></el-form-item>
        <el-form-item label="优惠说明"><el-input v-model="pojo.discountMessage"></el-input></el-form-item>

        <el-button type="primary" @click="handleSave()">保存</el-button>
        <el-button @click="dialogFormVisible = false" >关闭</el-button>
    </el-form>
  </el-dialog>
</div>
</template>
<script>
import shopApi from '@/api/shop'
export default {
  data() {
    return {
      list: [],
      total: 0, // 总记录数
      currentPage: 1, // 当前页
      pageSize: 10, // 每页大小
      searchMap: {}, // 查询条件
      dialogFormVisible: false, // 编辑窗口是否可见
      pojo: {}, // 编辑表单绑定的实体对象
      cityList: [], // 城市列表
      id: '' // 当前用户修改的ID
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      shopApi.search(this.currentPage, this.pageSize, this.searchMap).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
      })
    },
    handleSave() {
      shopApi.update(this.id, this.pojo).then(response => {
        this.$message({
          message: response.message,
          type: (response.flag ? 'success' : 'error')
        })
        if (response.flag) { // 如果成功
          this.fetchData() // 刷新列表
        }
      })
      this.dialogFormVisible = false // 关闭窗口
    },
    handleEdit(id) {
      this.id = id
      this.dialogFormVisible = true // 打开窗口
      if (id !== '') { // 修改
        shopApi.findById(id).then(response => {
          if (response.flag) {
            this.pojo = response.data
          }
        })
      } else {
        this.pojo = {} // 清空数据
      }
    },
    handleDelete(id) {
      this.$confirm('确定要删除此纪录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        shopApi.deleteById(id).then(response => {
          this.$message({ message: response.message, type: (response.flag ? 'success' : 'error') })
          if (response.flag) {
            this.fetchData() // 刷新数据
          }
        })
      })
    }
  }
}
</script>
